package com.tan.config;

import com.tan.po2.UserDao;
import com.tan.po2.UserService;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.*;

@Configuration//表示MyConfig是一个配置类，并且MyConfig这个类也会被创建到容器中单实例
@ComponentScan({"com.tan","com.tan.po3"})
@Import(MyConfig2.class)//ImportResource引入bean.xml Import引入configuration标注类
@PropertySource({"classpath:message.properties"})
public class MyConfig {
    //@Bean(name="name名字",initMethod = "初始化方法",destroyMethod = "销毁方法")
    @Bean
    @Scope("singleton")//作用域
    public UserService userService(@Autowired UserDao userDao){//@Autowired优先按照类型注入，如果有多个按照名字注入，名字就是参数名字
        UserService userService=new UserService();
        userService.setUserDao(userDao);
        System.out.println(userDao);
        return userService;
    }
    @Bean
    public UserDao userDao(){
        UserDao userDao=new UserDao();
        System.out.println("=======");
        return userDao;
    }
    @Bean
    public UserDao userDao2(){
        return new UserDao();
    }
}
